package com.wms.ymcc.service.impl;

import com.wms.ymcc.constant.ValidationConstants;
import com.wms.ymcc.domain.MediaFile;
import com.wms.ymcc.service.ServicePro;
import com.alibaba.fastjson.JSONObject;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.client.producer.SendStatus;
import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.stereotype.Service;

/**
 * @author : 阿盛哟
 * @description : 发送消息
 * @createDate : 2025/6/4 17:22
 */
@Service
public class ServiceProImpl implements ServicePro {

    @Autowired
    private RocketMQTemplate rocketMQTemplate;

    @Override
    public boolean sendMessage(MediaFile message) {
        SendResult result = rocketMQTemplate.syncSend(
                ValidationConstants.ROCKETMQ_TOPIC_MEDIA+":"+ValidationConstants.ROCKETMQ_TAGS_MEDIA,
                MessageBuilder.withPayload(JSONObject.toJSONString(message)).build());

        // 发送成功和失败的结果。
        return result.getSendStatus() == SendStatus.SEND_OK;
    }
}